package onjava.advance.ch01.sec11;

import static onjava.advance.ch01.sec11.Outcome.*;

/**
 * 使用enum分发
 *
 * @author yangdc
 * @date 2025/7/1
 */
public enum RoShamBo2 implements Competitor<RoShamBo2> {
    // paper scissors rock
    PAPER(DRAW, LOSE, WIN),
    SCISSORS(WIN, DRAW, LOSE),
    ROCK(LOSE, WIN, DRAW);

    private Outcome vPAPER, vSCISSORS, vROCK;

    RoShamBo2(Outcome paper, Outcome scissors, Outcome rock) {
        this.vPAPER = paper;
        this.vSCISSORS = scissors;
        this.vROCK = rock;
    }

    @Override
    public Outcome compete(RoShamBo2 it) {
        switch(it) {
            case PAPER: return vPAPER;
            case SCISSORS: return vSCISSORS;
            case ROCK: return vROCK;
            default: throw new IllegalArgumentException("Invalid RoShamBo2 value: " + it);
        }
    }

    public static void main(String[] args) {
        RoShamBo.play(RoShamBo2.class, 20);
    }
}

